package com.xintonghua.bussiness.ui.fragment.client.user;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.Contant;
import com.xintonghua.bussiness.bean.HairdressingTestBean;
import com.xintonghua.bussiness.bean.UserInfoBean;
import com.xintonghua.bussiness.ui.CustomerActivity;
import com.xintonghua.bussiness.util.AbstractBaseAdapter;
import com.xintonghua.bussiness.util.JsonUtil;
import com.xintonghua.bussiness.util.JumpUtils;
import com.xintonghua.bussiness.util.MyState;
import com.xintonghua.bussiness.util.ViewHolder;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 客户信息====》美容测试
 * 作者：wanxianyi
 * 时间：2018/3/5.
 * 包名：com.xintonghua.bussiness.ui.fragment.client.user
 */

public class HairdressingTestActivity extends BaseActivity {
    @BindView(R.id.lv_list)
    ListView lvList;

//                bun3.putSerializable("data0", (Serializable) contantbean);
//                bun3.putSerializable("data1", (Serializable) userInfoBean);


    Contant contantbean;

    UserInfoBean userInfoBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hairressing_test);
        ButterKnife.bind(this);
        contantbean = (Contant) JumpUtils.getSerializable(this, "data0");
        userInfoBean = (UserInfoBean) JumpUtils.getSerializable(this, "data1");
        initUI();
    }

    @Override
    public void initUI() {
        super.initUI();
        onSimpleActionBar();
        setSimpleActionBar("美容测试", "历史", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bun3 = new Bundle();
                bun3.putSerializable("data0", (Serializable) contantbean);
                JumpUtils.jumptoB(HairdressingTestActivity.this, MeiRongTestHistoryRecordActivity.class, bun3);

            }
        });
        getNetData();
    }

    List<HairdressingTestBean> list_bean;

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        try {
            switch (order) {
                case MyState.requestOne:
                    list_bean = JsonUtil.getListByJsonString(data.toString(), HairdressingTestBean.class);
                    initListView();
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getNetData() {
        httpCent.getBeautyType(this, MyState.requestOne);
    }

    public void initListView() {

        lvList.setAdapter(new AbstractBaseAdapter<HairdressingTestBean>(list_bean) {
            @Override
            public View getAdapterViewAtPosition(int position, View convertView, ViewGroup parent) {

                if (convertView == null) {
                    convertView = LayoutInflater.from(HairdressingTestActivity.this).inflate(R.layout.activity_customers, null);
                }
                TextView tv_type = ViewHolder.get(convertView, R.id.tv_type);//LayoutInflater.from(HairdressingTestActivity.this).inflate(R.layout.activity_customers, null);

                FrameLayout fl_content = ViewHolder.get(convertView, R.id.fl_content);

                if (position == 0) {
                    fl_content.setBackgroundResource(R.drawable.layer_list_selector_layer_top);
                } else if (position == list_bean.size() - 1) {
                    fl_content.setBackgroundResource(R.drawable.layer_list_selector_bottom);
                } else {
                    fl_content.setBackgroundResource(R.drawable.layer_list_selector_layer_center);
                }
                HairdressingTestBean bean = getItem(position);
                tv_type.setText("" + bean.getName());
                return convertView;
            }
        });
        lvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Bundle bun=new Bundle();
                bun.putSerializable("data0",contantbean);
                bun.putSerializable("data1",(Serializable) list_bean.get(i));
                JumpUtils.jumptoB(HairdressingTestActivity.this, MeiRongTestHomeActivity.class,bun);
            }
        });
    }
}